package com.tuyue.police.util;


import lombok.extern.log4j.Log4j;

import java.io.File;
import java.io.FileOutputStream;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/1/31.
 * @Modified By:
 */
@Log4j
public class FileUtil {

    /**
     * 上传单文件
     * @param file          文件byte
     * @param filePath      文件存放路径
     * @param fileName      文件名
     * @param imgAddress    application.properties 配置的文件夹名称
     * @return
     * @throws Exception
     */
    public static String uploadFile(byte[] file, String filePath, String fileName,String imgAddress) throws Exception {

        File targetFile = new File(filePath);
        if(!targetFile.exists()){
            targetFile.mkdirs();
        }
        log.info("【地址】："+filePath+fileName);
        FileOutputStream out = new FileOutputStream(filePath+fileName);
        out.write(file);
        out.flush();
        out.close();
        return imgAddress+fileName;
    }
}
